// @ts-ignore
/* eslint-disable */
import { request } from 'umi';
import { CreateUserReq, CreateUserResp, UpdateUserReq, UserItem } from './data';
import store from 'store';

export async function getAdminList(
  params: {
    /** 当前的页码 */
    current?: number;
    /** 页面的容量 */
    pageSize?: number;
  },
  options?: { [key: string]: any },
) {
  return request<{
    data: UserItem[];
    /** 列表的内容总数 */
    total?: number;
    success?: boolean;
  }>('/api/users', {
    method: 'GET',
    params: {
      ...params,
    },
    ...(options || {}),
  });
}

export async function createUser(data: { [key: string]: any }, options?: { [key: string]: any }) {
  return request<CreateUserResp>('/api/users', {
    data,
    method: 'POST',
    ...(options || {}),
  });
}

export async function updateUser(
  id: number,
  data: { [key: string]: any },
  options?: { [key: string]: any },
) {
  return request<UpdateUserReq>(`/api/users/${id}`, {
    data,
    method: 'PUT',
    ...(options || {}),
  });
}
